package com.jimmy.medical.controller;

import com.jimmy.medical.entity.Message;
import com.jimmy.medical.entity.OrderExceptionData;
import com.jimmy.medical.entity.OrderExecutionRecord;
import com.jimmy.medical.entity.PhoneCall;
import com.jimmy.medical.model.FeeInfo;
import com.jimmy.medical.service.IPhysicalCheckFlowOrderService;
import com.jimmy.medical.util.AjaxUtils;
import com.jimmy.medical.util.Func_T;
import com.jimmy.medical.model.AjaxResult;
import com.jimmy.medical.model.SignInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/physicalCheckFlow")
public class PhysicalCheckFlowOrderController {

    @Autowired
    private IPhysicalCheckFlowOrderService physicalCheckFlowOrderService;

    /**
     * 确认接单
     *
     * @param userId
     * @param： flowOrderId
     * @return
     */
    @RequestMapping("/affirm")
    @ResponseBody
    public AjaxResult<Long> affirm(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveAffirmInfo(flowOrderId, userId);
            }
        });
    }

    /**
     * 备单登记
     *
     * @param signInfo
     * @return
     */
    @RequestMapping("/sign")
    @ResponseBody
    public AjaxResult<Long> sign(final SignInfo signInfo) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveSignInfo(signInfo);
            }
        });
    }

    /**
     * 备单核验
     *
     * @param flowOrderId
     * @param userId
     * @param photoIds
     * @return
     */
    @RequestMapping("/signCheck")
    @ResponseBody
    public AjaxResult<Long> signCheck(final Long flowOrderId, final Long userId, final String photoIds) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveSignCheckInfo(flowOrderId, userId, photoIds);
            }
        });
    }

    /**
     * 电话通知
     *
     * @param call
     * @return
     */
    @RequestMapping("/signNoticeToCustomer")
    @ResponseBody
    public AjaxResult<Long> signNoticeToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveSignNoticeInfo(call);
            }
        });
    }

    /**
     * 短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/signMessageToCustomer")
    @ResponseBody
    public AjaxResult<Long> signMessageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveSignMessageFlow(message);
            }
        });
    }

    /**
     * 提交备单
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/submitSign")
    @ResponseBody
    public AjaxResult<String> submitSign(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                physicalCheckFlowOrderService.submitSign(flowOrderId, userId);
                return "200";
            }
        });
    }

    /**
     * 陪检接号
     *
     * @param userId
     * @param flowOrderId
     * @return
     */
    @RequestMapping("/accept")
    @ResponseBody
    public AjaxResult<Long> accept(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveAcceptInfo(flowOrderId, userId);
            }
        });
    }

    /**
     * 电话通知
     *
     * @param call
     * @return
     */
    @RequestMapping("/noticeToCustomer")
    @ResponseBody
    public AjaxResult<Long> noticeToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveNoticeInfo(call);
            }
        });
    }

    /**
     * 短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/messageToCustomer")
    @ResponseBody
    public AjaxResult<Long> messageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveMessageFlow(message);
            }
        });
    }

    /**
     * 整理客户资料
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/collating")
    @ResponseBody
    public AjaxResult<Long> collating(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveCollatingInfo(flowOrderId, userId);
            }
        });
    }

    /**
     * 自检仪容
     *
     * @param flowOrderId
     * @param userId
     * @param photoId
     * @return
     */
    @RequestMapping("/checkAppearance")
    @ResponseBody
    public AjaxResult<Long> checkAppearance(final Long flowOrderId, final Long userId, final Long photoId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveAppearance(flowOrderId, userId, photoId);
            }
        });
    }

    /**
     * 费用处理界面
     *
     * @param flowOrderId
     * @return
     */
    @RequestMapping("/goFeeProcess")
    @ResponseBody
    public AjaxResult<FeeInfo> goFeeProcess(final Long flowOrderId) {
        return AjaxUtils.process(new Func_T<FeeInfo>() {
            @Override
            public FeeInfo invoke() throws Exception {
                return physicalCheckFlowOrderService.getMemberFeeInfo(flowOrderId);
            }
        });
    }

    /**
     * 费用处理
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/feeProcess")
    @ResponseBody
    public AjaxResult<Long> feeProcess(final Long flowOrderId, final Long userId) {
        if(physicalCheckFlowOrderService.isFeeProcess(flowOrderId)) {
            //已处理
            return AjaxUtils.process(new Func_T<Long>() {
                @Override
                public Long invoke() throws Exception {
                    return physicalCheckFlowOrderService.saveFeeProcess(flowOrderId, userId);
                }
            });
        } else {
            AjaxResult result = new AjaxResult();
            result.setSuccess(false);
            result.setMessage("当前用户存在未处理费用,无法提交费用处理");
            return result;
        }
    }

    /**
     * 陪检
     *
     * @param flowOrderId
     * @param userId
     * @param photoIds
     * @return
     */
    @RequestMapping("/physicalCheck")
    @ResponseBody
    public AjaxResult<Long> physicalCheck(final Long flowOrderId, final Long userId, final String photoIds) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.savePhysicalCheck(flowOrderId, userId, photoIds);
            }
        });
    }

    /**
     * 提交陪检
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/submitPhysicalCheck")
    @ResponseBody
    public AjaxResult<String> submitPhysicalCheck(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                physicalCheckFlowOrderService.submitPhysicalCheck(flowOrderId, userId);
                return "200";
            }
        });
    }

    /**
     * 取报告接单
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/reportAffirm")
    @ResponseBody
    public AjaxResult<Long> reportAffirm(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveReportAffirmInfo(flowOrderId, userId);
            }
        });
    }

    /**
     * 取体检报告
     *
     * @param flowOrderId
     * @param userId
     * @param photoIds
     * @return
     */
    @RequestMapping("/takeReport")
    @ResponseBody
    public AjaxResult<Long> takeReport(final Long flowOrderId, final Long userId, final String photoIds) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveTakeReportInfo(flowOrderId, userId, photoIds);
            }
        });
    }

    /**
     * 电话通知
     *
     * @param call
     * @return
     */
    @RequestMapping("/reportNoticeToCustomer")
    @ResponseBody
    public AjaxResult<Long> reportNoticeToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveReportNoticeInfo(call);
            }
        });
    }

    /**
     * 短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/reportMessageToCustomer")
    @ResponseBody
    public AjaxResult<Long> reportMessageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.saveReportMessageFlow(message);
            }
        });
    }

    /**
     * 进入体检报告录入界面
     * @param flowOrderId
     * @return
     */
    @RequestMapping("/goPhysicalCheckReport")
    @ResponseBody
    public AjaxResult<List<OrderExceptionData>> goPhysicalCheckReport(final Long flowOrderId) {
        return AjaxUtils.process(new Func_T<List<OrderExceptionData>>() {
            @Override
            public List<OrderExceptionData> invoke() throws Exception {
                return physicalCheckFlowOrderService.getOrderExceptionDataList(flowOrderId);
            }
        });
    }

    /**
     * 提交体检报告
     * @param record
     * @param exceptionData
     * @return
     */
    @RequestMapping("/physicalCheckReport")
    @ResponseBody
    public AjaxResult<Long> physicalCheckReport(final OrderExecutionRecord record, final String exceptionData, final String diagnoseData) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return physicalCheckFlowOrderService.savePhysicalCheckRecord(record, exceptionData, diagnoseData);
            }
        });
    }

    /**
     * 提交陪检报告
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/submitReport")
    @ResponseBody
    public AjaxResult<String> submitReport(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                physicalCheckFlowOrderService.submitReport(flowOrderId, userId);
                return "200";
            }
        });
    }
}
